package com.module.user.ui.me.adapter

import android.widget.RatingBar
import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.module.user.R


class ItemAdapter(list: MutableList<ItemEntity>) :
    BaseSectionQuickAdapter<ItemEntity, BaseViewHolder>(
        R.layout.user_fragment_me_head_item,
        R.layout.user_fragment_me_item,
        list
    ) {


    override fun convertHeader(helper: BaseViewHolder, item: ItemEntity) {
        if (item.leftImg != 0) helper.setImageResource(R.id.me_left_image, item.leftImg!!)
        if (item.rightImg != 0) helper.setImageResource(R.id.me_right_image, item.rightImg!!)
        if (item.itemMsg != 0) helper.setText(R.id.me_msg, context.getString(item.itemMsg!!))

        helper?.setGone(R.id.me_line, item.bottomLine!!)
    }

    override fun convert(holder: BaseViewHolder, item: ItemEntity) {
        if (item.data != null) {
            if (item.data!!.img != 0) holder.setImageResource(R.id.me_left_image, item.data!!.img!!)
            holder.setText(R.id.me_item_title, item.data!!.itemTitle)
            holder.setText(R.id.me_item_msg, item.data!!.itemMsg)

            holder?.setGone(R.id.me_line,item.data!!.bottomLine!!)

            var mRatingBar = holder.getView<RatingBar>(R.id.me_item_ratingBar)
            mRatingBar.rating = item.data!!.starRating!!.toFloat()

            // 0 启动  1 下载
            when (item.data?.tpye) {
                0 -> {
                    holder.setText(
                        R.id.me_rightTv,
                        context.getString(R.string.user_profile_start_up)
                    )
                }
                1 -> {
                    holder.setText(
                        R.id.me_rightTv,
                        context.getString(R.string.user_profile_download)
                    )
                }
            }

        }


    }


}